<?php

/**
 * BuddyPress - Create a Group
 *
 * In order to add additional customized tabs to the create group screen, add to functions.php
 * in customize_group_creation_tabs():
 * 		$bp->groups->group_creation_steps['group-example']['name'] = 'Example';
 *		$bp->groups->group_creation_steps['group-example']['position'] = 50;
 * Then in this file, create and additional step by checking:
 *		if ( bp_is_group_creation_step( 'group-example' ) )
 *
 * This form sends POST data to bp-groups-actions.php
 */

get_header( 'buddypress' ); ?>

	<div id="content">
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js "></script>
	<script>
		function populate_Cities() {
		var statesList = document.creategroupform.states;
		var stateValue = statesList[statesList.selectedIndex].value;
		$.post(ajaxurl, {'action': 'popCities', 'state': stateValue}, function(temp){
		if(document.creategroupform.cities){
		document.creategroupform.removeChild(document.getElementById('choose_city'));
		}
		var element=document.getElementById('choose_state');
		var newdiv =document.createElement('div');
		newdiv.setAttribute('id','choose_city');
		newdiv.innerHTML=temp;
		element.appendChild(newdiv);
		});
}
		</script>
		<div class="padder">
		
		<?php do_action( 'bp_before_create_group_content_template' ); ?>

		<form action="<?php bp_group_creation_form_action(); ?>" name="creategroupform" method="post" id="create-group-form" class="standard-form" enctype="multipart/form-data">
			<h3><?php _e( 'Create a Group For Your Organization', 'buddypress' ); ?> </h3>

			<p>Private Twyne Groups are designed for any types of organizations. Their main purpose is to join all members of an organization together where everyone can network about any topic.</p>
			<p>These Groups are also geared towards helping members find roommates and housing if moving to a brand new city.</p>
			<p><strong>Notice: Upon creation of your Group, you will recieve a Group Code via email and in your Twyne inbox. In order to protect your Group privacy, only users with the Group Code will be allowed to join. Instructions regarding what to do with the Group Code will be in the email.</strong></p>
			
			<?php do_action( 'bp_before_create_group' ); ?>

			<div class="item-list-tabs no-ajax" id="group-create-tabs" role="navigation">
				<ul>

					<?php bp_group_creation_tabs(); ?>

				</ul>
			</div>

			<?php do_action( 'template_notices' ); ?>

			<div class="item-body" id="group-create-body">

				<?php /* Group creation step 1: Basic group details */ ?>
				<?php if ( bp_is_group_creation_step( 'group-details' ) ) : ?>

					<?php do_action( 'bp_before_group_details_creation_step' ); ?>
					
					<p>All of the fields on this page can be changed after the Group is created.</p>
						
					<label for="group-name" id="group-name-label"><?php _e( 'Group Name (required)', 'buddypress' ); ?></label>
					<input type="text" name="group-name" id="group-name" aria-required="true" value="<?php bp_new_group_name(); ?>" />

					<label for="group-desc"><?php _e( 'Group Description (required)', 'buddypress' ); ?></label>
					<textarea name="group-desc" id="group-desc" aria-required="true">Example: Welcome to Example's group page! In this group you can post anything you want members of the group to see. Post to the Stream, send messages to other members, and use the housing tab if your in need of finding housing.</textarea>

					<!--<label for="group-create-city-textbox">Enter a city where your organization is centralized: </label>
					<input type="text" name="group-create-city-textbox" id="group-create-city-textbox" />
					
					<label for="group-create-state-textbox">Enter a state where your organization is centralized: </label>
					<input type="text" name="group-create-state-textbox" id="group-create-state-textbox" />
					-->	
					
					<label for="choose_state" id="choose_state_label">Choose the city and state that are closest to where your Group is located</label>
					<div id="choose_state">
						Select a state: <select name="states" onChange="populate_Cities()">
							<option selected="selected">Choose a state</option>
								<?php
                                echo "\n";
                                $states=$GLOBALS[wpdb]->get_col(
                                            "
                                                SELECT distinct description 
                                                FROM wp_bp_groups 
                                                WHERE status='public'
												ORDER BY description
                                            ");                        
                                    foreach ($states as $value) {
                                        echo "<option value=$value>$value</option>\n";
                                    };
                                ?>
							
						</select>
					</div><!--choose_state -->
					
					<?php
					do_action( 'bp_after_group_details_creation_step' );
					do_action( 'groups_custom_group_fields_editable' ); // @Deprecated

					wp_nonce_field( 'groups_create_save_group-details' ); ?>

				<?php endif; ?>

				<?php /* Group creation step 2: Group settings */ ?>
				<?php if ( bp_is_group_creation_step( 'group-settings' ) ) : ?>

					<input type="hidden" name="group-status" value="private"/>

					<!--Group Admins and Mods only-->
					<input type="hidden" name="group-invite-status" value="mods"<?php bp_group_show_invite_status_setting( 'mods' ); ?> />

					<p id="mods-description">As the creator of this private Group, you will be the Group moderator. Group moderators have additional privledges over regular members of a Group, including the ability to delete members and delete Stream posts from other memebers.</p>
					<p id="mods-description">After the group is created, when viewing your Group, use the 'Members' tab to specify any additional members you would like to add as a moderator to this Group.</p>
					
					<div class="">
						<label for="official-group" id="official-group-description"><strong>OFFICIAL ORGANIZATIONS: Since anyone can create a Group, we want to ensure that the members of your Group know if it was made officially by your organization. If you are creating this Group as an official representation of an organization, please check the "Send Request" option below and we will contact you to give it our "Official Group" stamp.</label>
						<ul>
							<li>Send request: <input type="radio" name="official-group" id="official-group" value="official"/></li>
							<li>Skip this step: <input type="radio" name="official-group"  id="official-group" value="unofficial"/><li/>
						<ul>
					</div>
					
					<?php if ( bp_is_active( 'forums' ) ) : ?>

						<h4><?php _e( 'Group Forums', 'buddypress' ); ?></h4>

						<?php if ( bp_forums_is_installed_correctly() ) : ?>

							<p><?php _e( 'Should this group have a forum?', 'buddypress' ); ?></p>

							<div class="checkbox">
								<label><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php checked( bp_get_new_group_enable_forum(), true, true ); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
							</div>
						<?php elseif ( is_super_admin() ) : ?>

							<p><?php printf( __( '<strong>Attention Site Admin:</strong> Group forums require the <a href="%s">correct setup and configuration</a> of a bbPress installation.', 'buddypress' ), bp_core_do_network_admin() ? network_admin_url( 'settings.php?page=bb-forums-setup' ) :  admin_url( 'admin.php?page=bb-forums-setup' ) ); ?></p>

						<?php endif; ?>

					<?php endif; ?>
					
					<?php wp_nonce_field( 'groups_create_save_group-settings' ); ?>

				<?php endif; ?>

				<?php /* Group creation step 3: Avatar Uploads */ ?>
				<?php if ( bp_is_group_creation_step( 'group-avatar' ) ) : ?>

					<?php do_action( 'bp_before_group_avatar_creation_step' ); ?>

					<?php if ( 'upload-image' == bp_get_avatar_admin_step() ) : ?>

						<div class="left-menu">

							<?php bp_new_group_avatar(); ?>

						</div><!-- .left-menu -->

						<div class="main-column">
							<p><?php _e( "Upload an image to use as an avatar for this group. The image will be shown on the main group page, and in search results.", 'buddypress' ); ?></p>

							<p>
								<input type="file" name="file" id="file" />
								<input type="submit" name="upload" id="upload" value="<?php _e( 'Upload Image', 'buddypress' ); ?>" />
								<input type="hidden" name="action" id="action" value="bp_avatar_upload" />
							</p>

							<p><?php _e( 'To skip the avatar upload process, hit the "Next Step" button.', 'buddypress' ); ?></p>
						</div><!-- .main-column -->

					<?php endif; ?>

					<?php if ( 'crop-image' == bp_get_avatar_admin_step() ) : ?>

						<h3><?php _e( 'Crop Group Avatar', 'buddypress' ); ?></h3>

						<img src="<?php bp_avatar_to_crop(); ?>" id="avatar-to-crop" class="avatar" alt="<?php _e( 'Avatar to crop', 'buddypress' ); ?>" />

						<div id="avatar-crop-pane">
							<img src="<?php bp_avatar_to_crop(); ?>" id="avatar-crop-preview" class="avatar" alt="<?php _e( 'Avatar preview', 'buddypress' ); ?>" />
						</div>

						<input type="submit" name="avatar-crop-submit" id="avatar-crop-submit" value="<?php _e( 'Crop Image', 'buddypress' ); ?>" />

						<input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src(); ?>" />
						<input type="hidden" name="upload" id="upload" />
						<input type="hidden" id="x" name="x" />
						<input type="hidden" id="y" name="y" />
						<input type="hidden" id="w" name="w" />
						<input type="hidden" id="h" name="h" />

					<?php endif; ?>

					<?php do_action( 'bp_after_group_avatar_creation_step' ); ?>

					<?php wp_nonce_field( 'groups_create_save_group-avatar' ); ?>

				<?php endif; 
				
				/* Group creation step 4: Add additional steps here! */ ?>

				<?php do_action( 'groups_custom_create_steps' ); // Allow plugins to add custom group creation steps ?>

				<?php do_action( 'bp_before_group_creation_step_buttons' ); ?>

				<?php if ( 'crop-image' != bp_get_avatar_admin_step() ) : ?>

					<div class="submit" id="previous-next">

						<?php /* Previous Button */ ?>
						<?php if ( !bp_is_first_group_creation_step() ) : ?>

							<input type="button" value="<?php _e( 'Back to Previous Step', 'buddypress' ); ?>" id="group-creation-previous" name="previous" onclick="location.href='<?php bp_group_creation_previous_link(); ?>'" />

						<?php endif; ?>

						<?php /* Next Button */ ?>
						<?php if ( !bp_is_last_group_creation_step() && !bp_is_first_group_creation_step() ) : ?>

							<input type="submit" value="<?php _e( 'Next Step', 'buddypress' ); ?>" id="group-creation-next" name="save" />

						<?php endif;?>

						<?php /* Create Button */ ?>
						<?php if ( bp_is_first_group_creation_step() ) : ?>
							
							<p><strong>Notice: By clicking the button below, you are creating your Group! The following steps will walk you through additional settings and customization. After your Group is created, you will be able to change the information entered on this page.</p>
							<input type="submit" value="<?php _e( 'Create Group and Continue', 'buddypress' ); ?>" id="group-creation-create" name="save" />

						<?php endif; ?>

						<?php /* Finish Button */ ?>
						<?php if ( bp_is_last_group_creation_step() ) : ?>
								
							<input type="submit" value="<?php _e( 'Finish', 'buddypress' ); ?>" id="group-creation-finish" name="save" />

						<?php endif; ?>
					</div>

				<?php endif;?>

				<?php do_action( 'bp_after_group_creation_step_buttons' ); ?>

				<?php /* Don't leave out this hidden field */ ?>
				<input type="hidden" name="group_id" id="group_id" value="<?php bp_new_group_id(); ?>" />

				<?php do_action( 'bp_directory_groups_content' ); ?>

			</div><!-- .item-body -->

			<?php do_action( 'bp_after_create_group' ); ?>

		</form>
		
		
		<?php do_action( 'bp_after_create_group_content_template' ); ?>

		</div><!-- .padder -->
	</div><!-- #content -->

<?php get_sidebar( 'buddypress' ); ?>
<?php get_footer( 'buddypress' ); ?>
